home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_12
/
9n12124a
< prev
next >
Wrap
Text File
|
1991-09-22
|
2KB
|
89 lines
Listing 7
**********
#include <ctype.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int get_line(char *text_in, int size_text_in);
int put_line(char *text_out, int size_text_out);
void main()
{
#define SIZE_TEXT 1024
char text[SIZE_TEXT];
int size;
int spaces;
size = get_line(text, SIZE_TEXT);
spaces = put_line(text, size);
printf ("Sentence is %d \n", size);
printf ("And has %d spaces in it\n", spaces);
}
int get_line(text_in, size_text_in)
/* Gets a line of text and returns number of characters
(not counting newline) */
char *text_in ; /* Where to put the input text */
int size_text_in; /* Size of text_in */
{
int ret;
char *cret;
printf ("Enter Text : ");
cret = fgets(text_in, size_text_in, stdout);
if (cret !=NULL)
ret = strlen(text_in) - 1;
else
ret = - 1;
return ret;
}
put_line(text_out, size_text_out)
/* This outputs a line of text with the first letter of each word
upper-cased */
char *text_out; /* Text to output */
int size_text_out; /* Size of text */
{
int i;
int print_as_uppercase;
char chr;
int spaces;
print_as_uppercase = TRUE;
spaces = 0;
printf ("Text is : ");
for (i = 0; i < size_text_out; i++)
{
chr = text_out[i];
if (print_as_uppercase)
{
printf("%c",toupper(chr));
print_as_uppercase = FALSE;
}
else
{
printf("%c",tolower(chr));
}
if (isspace(chr))
{
print_as_uppercase = TRUE;
spaces++;
}
if (chr == '.' || chr == ',')
print_as_uppercase = TRUE;
}
printf("\n");
return spaces;
}
********